home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
distutils
/
dir_util.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
4KB
|
155 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__revision__ = '$Id: dir_util.py 39416 2005-08-26 15:20:46Z tim_one $'
import os
import sys
from types import *
from distutils.errors import DistutilsFileError, DistutilsInternalError
from distutils import log
_path_created = { }
def mkpath(name, mode = 511, verbose = 0, dry_run = 0):
if not isinstance(name, StringTypes):
raise DistutilsInternalError, "mkpath: 'name' must be a string (got %r)" % (name,)
name = os.path.normpath(name)
created_dirs = []
if os.path.isdir(name) or name == '':
return created_dirs
if _path_created.get(os.path.abspath(name)):
return created_dirs
(head, tail) = os.path.split(name)
tails = [
tail]
while head and tail and not os.path.isdir(head):
(head, tail) = os.path.split(head)
tails.insert(0, tail)
for d in tails:
head = os.path.join(head, d)
abs_head = os.path.abspath(head)
if _path_created.get(abs_head):
continue
log.info('creating %s', head)
if not dry_run:
try:
os.mkdir(head)
created_dirs.append(head)
except OSError:
exc = None
raise DistutilsFileError, "could not create '%s': %s" % (head, exc[-1])
except:
None<EXCEPTION MATCH>OSError
None<EXCEPTION MATCH>OSError
_path_created[abs_head] = 1
return created_dirs
def create_tree(base_dir, files, mode = 511, verbose = 0, dry_run = 0):
need_dir = { }
for file in files:
need_dir[os.path.join(base_dir, os.path.dirname(file))] = 1
need_dirs = need_dir.keys()
need_dirs.sort()
for dir in need_dirs:
mkpath(dir, mode, dry_run = dry_run)
def copy_tree(src, dst, preserve_mode = 1, preserve_times = 1, preserve_symlinks = 0, update = 0, verbose = 0, dry_run = 0):
copy_file = copy_file
import distutils.file_util
if not dry_run and not os.path.isdir(src):
raise DistutilsFileError, "cannot copy tree '%s': not a directory" % src
try:
names = os.listdir(src)
except os.error:
(errno, errstr) = None
if dry_run:
names = []
else:
raise DistutilsFileError, "error listing files in '%s': %s" % (src, errstr)
except:
dry_run
if not dry_run:
mkpath(dst)
outputs = []
for n in names:
src_name = os.path.join(src, n)
dst_name = os.path.join(dst, n)
if preserve_symlinks and os.path.islink(src_name):
link_dest = os.readlink(src_name)
log.info('linking %s -> %s', dst_name, link_dest)
if not dry_run:
os.symlink(link_dest, dst_name)
outputs.append(dst_name)
continue
if os.path.isdir(src_name):
outputs.extend(copy_tree(src_name, dst_name, preserve_mode, preserve_times, preserve_symlinks, update, dry_run = dry_run))
continue
copy_file(src_name, dst_name, preserve_mode, preserve_times, update, dry_run = dry_run)
outputs.append(dst_name)
return outputs
def _build_cmdtuple(path, cmdtuples):
for f in os.listdir(path):
real_f = os.path.join(path, f)
if os.path.isdir(real_f) and not os.path.islink(real_f):
_build_cmdtuple(real_f, cmdtuples)
continue
cmdtuples.append((os.remove, real_f))
cmdtuples.append((os.rmdir, path))
def remove_tree(directory, verbose = 0, dry_run = 0):
grok_environment_error = grok_environment_error
import distutils.util
log.info("removing '%s' (and everything under it)", directory)
if dry_run:
return None
cmdtuples = []
_build_cmdtuple(directory, cmdtuples)
for cmd in cmdtuples:
try:
apply(cmd[0], (cmd[1],))
abspath = os.path.abspath(cmd[1])
if _path_created.has_key(abspath):
del _path_created[abspath]
continue
except (IOError, OSError):
exc = None
log.warn(grok_environment_error(exc, 'error removing %s: ' % directory))
continue
def ensure_relative(path):
(drive, path) = os.path.splitdrive(path)
if sys.platform == 'mac':
return os.sep + path
elif path[0:1] == os.sep:
path = drive + path[1:]
return path